package com.emapp.lccode.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.chad.library.adapter.base.BaseQuickAdapter
import com.emapp.lccode.R
import com.emapp.lccode.base.BaseConfig
import com.emapp.lccode.bean.Project
import com.emapp.lccode.databinding.ListitemProjectGridBinding

class ProjectGridAdapter : BaseQuickAdapter<Project, ProjectGridAdapter.VH>() {

    class VH(
        parent: ViewGroup,
        val binding: ListitemProjectGridBinding = ListitemProjectGridBinding.inflate(
            LayoutInflater.from(parent.context), parent, false
        ),
    ) : RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
        return VH(parent)
    }

    override fun onBindViewHolder(holder: VH, position: Int, item: Project?) {
        if (item == null) return
        holder.binding.tvName.text = item.sort_name
        Glide.with(context)
            .load(BaseConfig.ROOT_URL + item.small_thumb)
            .centerCrop()
            .error(R.drawable.img_project_fail)
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .into(holder.binding.ivAvatar)
    }

}